﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using WPF_GUI.AirportSVC;
using System.ComponentModel;

namespace WPF_GUI.ViewModels
{
    class DisplayedRouteWindowViewModel : ChildWindowViewModel
    {
        private ObservableCollection<RouteNode> _routeNodes;

        public DisplayedRouteWindowViewModel(MainPageViewModel parentViewModel)
            : base(parentViewModel)
        {
            _routeNodes = new ObservableCollection<RouteNode>();
            
            parentViewModel.PropertyChanged += OnSelectedPlaneChanged;
        }

        public ObservableCollection<RouteNode> RouteNodes
        {
            get
            {
                return _routeNodes;
            }

            set
            {
                if (_routeNodes != value)
                {
                    _routeNodes = value;
                    OnPropertyChanged("RouteNodes");
                }
            }
        }

        private void OnSelectedPlaneChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName.Equals("SelectedPlane"))
            {
                if (_parentViewModel.SelectedPlane != null)
                {
                    RouteNodes = new ObservableCollection<RouteNode>(_parentViewModel.SelectedPlane.CurrentRoute.RouteNodes);
                }
                else
                {
                    RouteNodes = new ObservableCollection<RouteNode>();
                }
            }
        }
    }
}
